<template>
	<view>
		<!-- 轮播图 -->
		<uni-swiper-dot class="uni-swiper-dot-box" :info="data" :current="current" field="content">
			<swiper class="swiper-box" :current="swiperDotIndex" @change="changeSwiper">
				<swiper-item v-for="(item, index) in data" :key="index">
					<view class="swiper-item" @click="clickBannerItem(item)">
						<image :src="item.image" mode="aspectFill" :draggable="false" />
					</view>
				</swiper-item>
			</swiper>
		</uni-swiper-dot>
		<view style="margin: 20rpx;border-radius: 10rpx;">
			<up-notice-bar direction="column" :text="text1"></up-notice-bar>
			<br />
			<view class="action-buttons">
				<view @click.stop="handUp(item.id,index)">
					<svg class="icon" aria-hidden="true">
						<use xlink:href="#icon-lishijilu"></use>
					</svg>
					<view>最新活动</view>
				</view>
				<view>
					<svg class="icon" aria-hidden="true">
						<use xlink:href="#icon-lishijilu"></use>
					</svg>
					<view>热门活动</view>
				</view>
				<view @click.stop="star(item.id,index)">
					<svg class="icon" aria-hidden="true">
						<use xlink:href="#icon-lishijilu"></use>
					</svg>
					<view>报名最多</view>
				</view>
				<!-- <view @click.stop="star(item.id,index)">
					<svg class="icon" aria-hidden="true">
						<use xlink:href="#icon-lishijilu"></use>
					</svg>
					<view>{{item.collectCount}}</view>
				</view> -->
			</view>
			<br>
			<up-text type="warning" text="热门推荐"></up-text>
			<scroll-view @scrolltolower="handleIsBotton" refresherpulling="handleIsRefresh" style="height: 1150px"
				scroll-y="true" class="scroll-Y">
			<view class="wrap">
				<view class="item" v-for="(item, index) in activityList" :key="index">
					<uni-card @click="details(item.id)">
						<u-row>
							<u-col :span="item.img?8:12">
								<view>
									<view class="item-title">{{ item.title }}</view>
									<view class="message">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{ item.outline }}</view>
									
									<!-- 时间戳 -->
									<!-- <view class="time">发布于：{{ item.releaseTime }}</view> -->
								</view>
							</u-col>
							<u-col :span="4" style="height: 160rpx;">
								<image v-if="item.img" :src="config.baseUrl+item.img"></image>
			
							</u-col>
						</u-row>
						<u-row>
							<u-col :span="4">
								<view>
									<uni-tag :text="item.responsiblePerson" plain size="mini" type="warning">
									</uni-tag>
								</view>
							</u-col>
							<u-col :span="8" style="text-align: right;">
								{{item.releaseTime}}
							</u-col>
						</u-row>
						<!-- 用户信息 -->
			
						<!-- 图片容器 -->
			
						<!--活动简介 -->
			
						<!-- 点赞、浏览量、收藏 -->
						<view class="action-buttons">
							<view @click.stop="handUp(item.id,index)">
								<uni-icons v-if="!item.isHandUp" type="hand-up" size="26"></uni-icons>
								<uni-icons v-if="item.isHandUp" type="hand-up-filled" color="#FF8C00" size="26"></uni-icons>
								<view>{{item.handUpCount}}</view>
							</view>
							<view>
								<uni-icons type="eye" size="26"></uni-icons>
								<view>{{item.viewCount}}</view>
							</view>
							<view @click.stop="star(item.id,index)">
								<uni-icons v-if="!item.isCollect" type="star" size="26"></uni-icons>
								<uni-icons v-if="item.isCollect" type="star-filled" color="#FF8C00" size="26"></uni-icons>
								<view>{{item.collectCount}}</view>
							</view>
						</view>
					</uni-card>
				</view>
			</view>
			</scroll-view>
		</view>

		<!-- <up-swiper :list="list2" keyName="image" showTitle :autoplay="false" circular></up-swiper> -->
	</view>
</template>

<script setup>
	import {
		getDetails
	} from '@/store/activity';
	import {onMounted,
		ref
	} from 'vue';
	import {
		releaseList
	} from "@/api/system/activity";
	import {
		signUp,
		signIn,
		signInInfo,
		signUpInfo
	} from "@/api/system/record"
	
	import config from "@/config";
	const text1 = ref(["111", "222"])
	const current = ref(0);
	const swiperDotIndex = ref(0);
	const data = ref([{
			image: '/static/images/banner/banner01.jpg',
			url: "activity/details?id=1778670161109229569"
		},
		{
			image: '/static/images/banner/banner02.jpg'
		},
		{
			image: '/static/images/banner/banner03.jpg'
		}
	]);

	const keyword = ref('');
	const activityList = ref([]);
	const loading = ref(true);
	const total = ref(0);

	//分页信息
	const pageInfo = ref({
		pageNum: 1,
		pageSize: 10
	})
	//获取数据
	function getList(search) {
		loading.value = true;
		releaseList({
			"keyword": keyword.value
		}).then(response => {
			total.value = response.total;
			if (search) {
				activityList.value = response.rows
			} else if (activityList.value.length < total.value) {
				activityList.value.push(...response.rows);
			}
			loading.value = false;
		});
	}
	onMounted(() => {
		getList();
		
		datails()
	})

	function details(id) {
		console.log(id);
		uni.navigateTo({
			url: '/pages/activity/details?id=' + id
		});
	}
	const handUp = (id, index) => {
		signUp(id).then(res => {

			activityList.value[index].isHandUp = res.data
			res.data ? activityList.value[index].handUpCount++ : activityList.value[index].handUpCount--

		})
	}
	const star = (id, index) => {
		signIn(id).then(res => {
			activityList.value[index].isCollect = res.data
			res.data ? activityList.value[index].collectCount++ : activityList.value[index].collectCount--
		})
	}

	//到达底部
	const handleIsBotton = () => {
		pageInfo.value.pageNum++;
		getList();
	}

	//到达底部
	const handleIsRefresh = () => {
		pageInfo.value.pageNum = 1;
		getList();
	}
	function clickBannerItem(item) {
		uni.navigateTo({
			url: item.url
		});
	};

	function changeSwiper(e) {
		current.value = e.detail.current
	}



	function saoma() {
		console.log("扫码签到");
		uni.scanCode({
			success: function(res) {
				console.log('条码类型：' + res.scanType);
				console.log('条码内容：' + res.result);
			}
		});
	}

	function datails() {
		if (getDetails() != '') {
			uni.navigateTo({
				url: '/pages/activity/details?id=' + getDetails()
			})
		}
	}
</script>


<style lang="scss">
	/* #ifndef APP-NVUE */
	page {
		display: flex;
		flex-direction: column;
		box-sizing: border-box;
		background-color: #fff;
		min-height: 100%;
		height: auto;
	}

	view {
		font-size: 14px;
		line-height: inherit;
	}

	/* #endif */

	.text {
		text-align: center;
		font-size: 26rpx;
		margin-top: 10rpx;
	}

	.grid-item-box {
		flex: 1;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding: 15px 0;
	}

	.uni-margin-wrap {
		width: 690rpx;
		width: 100%;
		;
	}

	.swiper {
		height: 300rpx;
	}

	.swiper-box {
		height: 150px;
	}

	.swiper-item {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		justify-content: center;
		align-items: center;
		color: #fff;
		height: 300rpx;
		line-height: 300rpx;
	}

	.action-buttons {
		text-align: center;
		display: flex;
		justify-content: space-around;
		margin-top: 5px;
	}

	.icon {
		width: 1em;
		height: 1em;
		vertical-align: -0.15em;
		fill: currentColor;
		overflow: hidden;
		font-size: 80rpx;
	}

	@media screen and (min-width: 500px) {
		.uni-swiper-dot-box {
			width: 400px;
			/* #ifndef APP-NVUE */
			margin: 0 auto;
			/* #endif */
			margin-top: 8px;
		}

		.image {
			width: 100%;
		}
	}
</style>